package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.login.GuiguLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "订单管理")
@RestController
@RequestMapping("/api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;

	/**
	 * 订单确认
	 * @param tradeVo
	 * @return
	 */
	@GuiguLogin
	@PostMapping("/trade")
	public Result trade(@RequestBody TradeVo tradeVo){
		return Result.ok(orderInfoService.trade(tradeVo));
	}

	/**
	 * 提交订单(立即结算)
	 * @param orderInfoVo
	 * @return
	 */
	@GuiguLogin
	@PostMapping("/submitOrder")
	public Result submitOrder(@RequestBody OrderInfoVo orderInfoVo){
		return Result.ok(orderInfoService.submitOrder(orderInfoVo));
	}

	/**
	 * 取消订单
	 * @param orderNo
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/cancelOrder/{orderNo}")
	public Result cancelOrder(@PathVariable("orderNo")String orderNo){
		orderInfoService.cancelOrder(orderNo);
		return Result.ok();
	}

	/**
	 * 查询订单信息
	 * @param orderNo
	 * @return
	 */
	@GuiguLogin
	@GetMapping("getOrderInfo/{orderNo}")
	public Result getOrderInfo(@PathVariable("orderNo")String orderNo){
		return Result.ok(orderInfoService.getOrderInfo(orderNo));
	}

	/**
	 * 分页查询用户订单列表
	 * @param page
	 * @param size
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/findUserPage/{page}/{size}")
	public Result findUserPage(@PathVariable("page") Integer page,
							   @PathVariable("size") Integer size){
		return Result.ok(orderInfoService.findUserPage(page,size));
	}


	/**
	 * 根据用户选择的支付渠道 获取对应的支付信息
	 * @param orderNo
	 * @param payWay
	 * @return
	 */
	@GuiguLogin
	@GetMapping("/getOrderPayInfo/{orderNo}/{payWay}")
	public Result getOrderPayInfo(@PathVariable("orderNo")String orderNo,
								  @PathVariable("payWay")String payWay){
		return Result.ok(orderInfoService.getOrderPayInfo(orderNo,payWay));
	}

}

